package slxy.jiangtao.dts.controller.business;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import slxy.jiangtao.dts.core.common.service.CommonService;
import slxy.jiangtao.dts.core.util.DateUtils;
import slxy.jiangtao.dts.entity.sys.DictionariesYear;

/**
 * Code must be sexy
 * Created by Jiang Tao on 2017/5/5.
 * 说明：定时任务集合
 */
@Component
public class TimingTaskController {
    @Autowired
    CommonService commonService;

    /**
     * 每年三月一号晚上一点添加下边年年度
     */
    @Scheduled(cron = "0 0 1 1 3 ?")
    public void addYearXia() {
        String right = DateUtils.getDate("yyyy");
        Integer left = Integer.parseInt(right) - 1;
        DictionariesYear dictionariesYear = new DictionariesYear();
        dictionariesYear.setName(left + "-" + right + " (下)");
        commonService.save(dictionariesYear);
    }

    /**
     * 每年九月一号晚上一点添加上边年年度
     */
    @Scheduled(cron = "0 0 1 1 9 ?")
    public void addYearShang() {
        String left = DateUtils.getDate("yyyy");
        Integer right = Integer.parseInt(left) + 1;
        DictionariesYear dictionariesYear = new DictionariesYear();
        dictionariesYear.setName(left + "-" + right + " (上)");
        commonService.save(dictionariesYear);
    }

    /**定时器配置测试*/
    /*@Scheduled(cron = "0/10 * * * * ?")
    public void test() {
        System.out.println("测试："+DateUtils.getDate("HH:mm:ss"));
    }*/
}
